package yz.mr.sort;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//对于Map端写出数据，进行排序，我们自定义排序，并且不需要Reduce
public class SortMapper extends Mapper<LongWritable, Text,SortStudent, NullWritable> {
    //这里的排序是根据key来排序，和value无关，所以对于实现compareTo的函数需要作为Key
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, SortStudent, NullWritable>.Context context) throws IOException, InterruptedException {
        //1500100001	施笑槐,22,女,文科六班,406
        String[] split = value.toString().split("\t");
        String id = split[0];
        String otherInfo = split[1];
        String[] split1 = otherInfo.split(",");
        SortStudent student = new SortStudent(id, split1[0], split1[1], split1[2], split1[3], Integer.parseInt(split1[4]));
        context.write(student,NullWritable.get());
    }
}
